﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IBS.Bll.Accounts;
using IBS.Bll.Authority;
using IBS.Bll.AutoPayments;
using IBS.Bll.Bills;
using IBS.Bll.Cards;
using IBS.Bll.KnowledgeBase;
using IBS.Bll.OperationDay;
using IBS.Bll.Payments;
using IBS.Bll.Security;
using IBS.Bll.Transfers;
using IBS.Dal;
using IBS.Model;
using IBS.ServiceContracts;
using Ninject;
using Ninject.Web.Common;

namespace IBS.Bll
{
    public class ServicesFactory
    {
        private IKernel kernel;
        private IKernel singleKernel;

        public void BuildKernel(IKernel kernel)
        {
            kernel.Bind<IAccountService>()
                .To<AccountService>();


            kernel.Bind<IAddressService>()
                .To<AddressService>();

            kernel.Bind<IAutoPaymentService>()
                                       .To<AutoPaymentService>();


            kernel.Bind<IAdmissionService>()
                .To<AdmissionService>();


            kernel.Bind<IAuthorityService>()
                .To<AuthorityService>();

            kernel.Bind<IBillService>()
               .To<BillService>();

            kernel.Bind<ICardService>()
                .To<CardService>();


            kernel.Bind<ICurrencyService>()
                .To<CurrencyService>();


            kernel.Bind<IKnowledgeBaseService>()
                .To<KnowledgeBaseService>();


            kernel.Bind<IOperationDayService>()
                .To<OperationDayService>();


            kernel.Bind<IPaymentService>()
                .To<PaymentService>();


            kernel.Bind<ISecurityService>()
                .To<SecurityService>();


            kernel.Bind<IStreetService>()
                  .To<StreetService>();


            kernel.Bind<ITransferService>()
                .To<TransferService>();
        }
        public ServicesFactory()
        {
            kernel = new StandardKernel();
            singleKernel = new StandardKernel();

            kernel.Bind<IIbsContext>()
                .To<IbsContext>()
                .InRequestScope();

            singleKernel.Bind<IIbsContext>()
                .To<IbsContext>()
                .InSingletonScope();

            BuildKernel(kernel);
            BuildKernel(singleKernel);
            

        }
        public T GetInstanceInSingleContextScope<T>()
        {
            return singleKernel.Get<T>();
        }
        public T GetInstance<T>()
        {
            return singleKernel.Get<T>();
        }
    }
}
